<?php

namespace control;
/*
*科目辅助余额表类
*/

class subjectAssetBalanceClass extends adIndexClass
{
    private const page  = 'subjectAssetBalance';
    private const title = '科目辅助余额表';
    public static bool $isFormat = false;//是否格式化数字

    private function js()
    {
        return <<<eof
<script>
</script>
eof;
    }


    /**
     * 模糊查询科目
     */
    public function getSubject(): bool|string
    {
        $component    = new componentClass();
        $val          = $this->post('keyword');//关键词
        $showParent   = (bool)$this->post('showParent');
        $json['data'] = [];
        $where        = " and coid='" . self::$coid . "' and assistAccount = '是' and (id in (select distinct b.subjectId from voucher as a join voucher_detail as b on a.id = b.orderId where 1=1 " . voucherClass::joinWhere() . ") or id in (select id from subject_assist where orderId = id and initMoney !=0))";
        if ($val) {
            $where .= " and (name like '%$val%' or code like '%$val%' or concat(code,' ',name) like '%$val%')";
        }


        $subjectIds = [];
        $all        = find(array('table' => 'subject', 'where' => "1=1 $where order by code asc"));
        foreach ($all['array'] as $array) {
            $res        = $component->loopSubject($array['id'], $where, $showParent);
            $subjectIds = array_merge($subjectIds, $res);
        }
        $subjectIds = array_unique($subjectIds);
        foreach ($subjectIds as $id) {
            $subject        = query('subject', "id = '$id'");
            $json['data'][] = array('title' => $subject['code'] . ' ' . $subject['name'], 'direction' => $subject['direction'], 'id' => $subject['id']);
        }
        $json['warn'] = 2;
        return json_encode($json, 320);
    }

    /*列表页-查询条件*/
    public function homeOptions($isAsync = true)
    {
        $subject = query("subject", "coid='" . self::$coid . "' and assistAccount = '是' and (id in (select distinct b.subjectId from voucher as a join voucher_detail as b on a.id = b.orderId where 1=1 " . voucherClass::joinWhere() . ") or id in (select id from subject_assist where orderId = id and initMoney !=0)) order by code");
        if (empty($subject['id'])) {
            $subject = query('subject', "coid = '" . self::$coid . "' order by code");
        }
        $maxDate = accountDetailsClass::getMaxDate();
        $minDate = accountDetailsClass::getMinDate();
        //生成查询表单
        $html = $this->tableShow([
            [
                [
                    "会计期间" => text(array("name" => "createTime", 'class' => 'width200', 'value' => static::rGet(self::$stid .self::$coid. 'SearchMonth') ?: date('Y-m', strtotime($maxDate)) . ' ~ ' . date('Y-m', strtotime($maxDate)), 'laydate' => ['type' => 'month', 'range' => '~', 'min' => "'{$minDate}'", 'max' => "'{$maxDate}'"])),
                    "科目"   => componentClass::selectText(array('name' => 'subjectId', 'title' => $subject['code']?($subject['code'] . ' ' . $subject['name']):'', 'cla' => self::page, 'fun' => 'getSubject', 'value' => $subject['id'])),
                    '客户' => clientProfileClass::kehuSelect(array('title' => '', 'name' => 'khid', 'fun' => 'getClientNameAndCode')),
                ],
                [
                    '供应商'  => supplierClass::supplierSelect(['name' => 'supplierId', 'fun' => 'getSupplier', 'title' => '']),
                    "员工" => selectMultiple(array('name' => 'staffId', 'table' => 'staff', 'where' => "1=1 order by orderNo asc", 'sqlId' => 'stid', 'sqlField' => 'name', 'class' => 'width200')),
                    '部门' => selectMultiple(array('name' => 'departmentId', 'field' => "concat(orderNo,name) as name,id", 'table' => 'department', 'where' => "1=1 order by orderNo asc", 'sqlId' => 'id', 'sqlField' => 'name', 'class' => 'width200')),
                ],
                [
                    "存货" => componentClass::selectText(['name' => 'materialId', 'title' => '', 'cla' => 'voucherEdit', 'fun' => 'getMaterial']),
                    "现金流" => selectMultiple(array('name' => 'cashId', 'field' => "concat(code,name) as name,id", 'table' => 'cash', 'where' => "coid='" . self::$coid . "' order by code asc", 'sqlId' => 'id', 'sqlField' => 'name', 'class' => 'width200')),
                    "项目" => selectMultiple(array('name' => 'projectId', 'field' => "concat(orderNo,name) as name,id", 'table' => 'project', 'where' => "coid='" . self::$coid . "' order by orderNo asc", 'sqlId' => 'id', 'sqlField' => 'name', 'class' => 'width200')),
                ]
            ]
        ],1);
        //返回
        if (!$isAsync) {
            return $html;
        } else {
            return json_encode(['html' => $html], 320);
        }
    }

    /*列表-查询条件*/
    public function home()
    {
        $html = $this->homeOptions(false);
        //控件
        $button = "";
        if ($this->power(self::page, "export")) {
            $button .= "  <a href='" . root . "control/adIndex.html?cla=" . $this->get('cla') . "&fun=exportData'><span class='spanButton'>导出</span></a>\n";
        }
        //返回
        return $this->homeFun($this->searchExecute([
            'html' => $html,
            'layout' => 'pop',
            'toolButton' => $button,
            'option' => '{fixed:true, row:2}'
        ]));
    }


    /*客户列表-查询结果*/
    public function homeSearch()
    {
        static::rSet(self::$stid .self::$coid. 'SearchMonth', $this->post('createTime'));;
        $json['html'] = $this->onlyMoneySearch();
        return json_encode($json, 320);
    }


    /**
     * 金额式
     */
    public function onlyMoneySearch(): string
    {
        $assetField = array(
            "khid"          => $this->post('khid'),
            "supplierId"    => $this->post('supplierId'),
            "staffId"       => $this->post('staffId'),
            "departmentId"  => $this->post('departmentId'),
            "materialId" => $this->post('materialId'),
            "cashId"        => $this->post('cashId'),
            "projectId"     => $this->post('projectId'),
        );
        $and        = search(array("=" => $assetField)) . " and a.id = '" . $this->post('subjectId') . "'";
        $arr        = $this->post('createTime') ? explode(' ~ ', $this->post('createTime')) : [date('Y-m', strtotime(accountDetailsClass::getMinDate())), date('Y-m', strtotime(accountDetailsClass::getMaxDate()))];
        $startMonth = trim($arr[0]);
        $endMonth   = end($arr);
        //获取查询结果
        //获取查询结果
        $page = $this->page([
            "table"   => "subject as a join voucher_detail as b on a.id = b.subjectId join voucher as c on b.orderId =c.id  where a.coid = '" . self::$coid . "' and c.isTemplate = '否'  $and UNION select b.khid,b.supplierId,b.staffId,b.departmentId,b.materialId,b.cashId,b.projectId,a.id as subjectId from subject as a join subject_assist as b on a.id = b.orderId",
            'field'   => 'b.khid,b.supplierId,b.staffId,b.departmentId,b.materialId,b.cashId,b.projectId,a.id as subjectId',
            "where"   => "a.coid = '" . self::$coid . "'  and b.initMoney !=0 $and order by khid,supplierId,staffId,departmentId,materialId,cashId,projectId asc",
            'pageNum' => 50,
            'union'   => "select ifnull(count(a.id),0) as num from subject  as a join voucher_detail as b on a.id = b.subjectId join voucher as c on b.orderId =c.id  where a.coid = '" . self::$coid . "' and c.isTemplate = '否' {$and}  UNION select ifnull(count(a.id),0) as num from subject as a join subject_assist as b on a.id = b.orderId where a.coid = '" . self::$coid . "' and b.initMoney !=0 {$and}",
        ]);
        static::rSet(self::$stid . self::page . 'sql', $page['fullSql']);
        static::rSet(self::$stid . self::page . 'subjectId', $this->post('subjectId'));
        static::rSet(self::$stid . self::page . 'time', $this->post('createTime'));
        self::$isFormat = true;
        $tr             = '';
        foreach ($page['array'] as $array) {
            $kehu        = query('kehu', "khid = '$array[khid]'");
            $supplier    = query('supplier', "id = '$array[supplierId]'");
            $staff       = query('staff', "stid = '$array[staffId]'");
            $department  = query('department', "id = '$array[departmentId]'");
            $material    = query('material', "id = '$array[materialId]'");
            $cash        = query('cash', "id = '$array[cashId]'");
            $project     = query('project', "id = '$array[projectId]'");
            $initResult  = $this->initMoney($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $startMonth, $array['subjectId']);
            $monthResult = $this->monthBalance($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $startMonth, $endMonth, $array['subjectId']);
            $balance     = $this->balance($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $endMonth, $array['subjectId']);
            $tr          .= $this->trHtml(array($kehu['orderNo'], $kehu['companyName'], $supplier['code'], $supplier['name'], $staff['orderNo'], $staff['name'],
                $department['orderNo'], $department['name'], $material['code'], $material['name'], $cash['code'], $cash['name'], $project['orderNo'],
                $project['name'], $initResult['jieMoney'], $initResult['daiMoney'], $monthResult['jieMoney'],
                $monthResult['daiMoney'], $balance['jieMoney'], $balance['daiMoney']));
        }
//        $sortStr = '<span class="table-sort"><i class="table-sort-asc"></i><i class="table-sort-desc"></i></span><span class="drag">&nbsp;</span>';
        // 月份选择器
        $monthSelector = componentClass::monthSelector(implode('~',$arr));
        $html = <<<eof
<table class="tableMany">
    <thead>
        <tr>
            <td sort-key="客户编码" rowspan="2" style="vertical-align: middle">客户编码</td>
            <td  rowspan="2" style="vertical-align: middle">客户名称</td>
            <td sort-key="供应商编码" rowspan="2" style="vertical-align: middle">供应商编码</td>
            <td rowspan="2" style="vertical-align: middle">供应商名称</td>
            <td sort-key="员工编码" rowspan="2" style="vertical-align: middle">员工编码</td>
            <td rowspan="2" style="vertical-align: middle">员工名称</td>
            <td sort-key="部门编码" rowspan="2" style="vertical-align: middle">部门编码</td>
            <td rowspan="2" style="vertical-align: middle">部门名称</td>
            <td sort-key="存货编码" rowspan="2" style="vertical-align: middle">存货编码</td>
            <td rowspan="2" style="vertical-align: middle">存货名称</td>
            <td sort-key="现金流编码" rowspan="2" style="vertical-align: middle">现金流编码</td>
            <td rowspan="2" style="vertical-align: middle">现金流名称</td>
            <td sort-key="项目编码" rowspan="2" style="vertical-align: middle">项目编码</td>
            <td rowspan="2" style="vertical-align: middle">项目名称</td>
            <td colspan="2" class="center">期初余额</td>
            <td colspan="2" class="center">本期发生额</td>
            <td colspan="2" class="center">期末余额 {$monthSelector['button']}</td>
        </tr>
        <tr>
            <td>借方</td>
            <td>贷方</td>
            <td>借方</td>
            <td>贷方</td>
            <td>借方</td>
            <td>贷方</td>
        </tr>
    </thead>
    <tbody>
       $tr
    </tbody>
</table>
eof;
        //返回
        return $page['hint'] .
            "<div class='acct-main-container'>
                <form name='listForm'>" .
                    $html .
                "</form>" .
                $monthSelector['html'].
            "</div>" .
            $this->style() .
            $this->js() .
            $page['button'] .
            clear;
    }

    /**
     * @return string
     */
    public function style(): string
    {
        return <<<eof
<style>
.tableMany thead tr:nth-of-type(2) {  
    background-color: #f2f2f2;
    color: #555;  
}
</style>
eof;
    }

    /**
     * 组成一行tr
     * @param $tr
     * @return string
     */
    public function trHtml($tr)
    {
        $html = '<tr>';
        foreach ($tr as $val) {
            $html .= "<td>$val</td>";
        }
        $html .= '</tr>';
        return $html;
    }

    /**
     * 修改列表样式
     * @return bool|string
     */
    public function changeTableStyle(): bool|string
    {
        $style = $this->post('style');

        if (!in_array($style, accountDetailsClass::styleOption)) {
            $json['warn'] = '请选择列表样式';
        } else {
            $json['warn'] = 2;
            static::rSet(self::page . 'tableStyle', $style);
        }
        return json_encode($json, 320);
    }

    /**
     * 期初余额
     * @param $khid
     * @param $supplierId
     * @param $staffId
     * @param $departmentId
     * @param $materialId
     * @param $cashId
     * @param $projectId
     * @param $startMonth
     * @param $subjectId
     * @return array
     */
    public function initMoney($khid, $supplierId, $staffId, $departmentId, $materialId, $cashId, $projectId, $startMonth, $subjectId): array
    {
        $assetField   = array(
            "khid"          => $khid,
            "supplierId"    => $supplierId,
            "staffId"       => $staffId,
            "departmentId"  => $departmentId,
            "materialId" => $materialId,
            "cashId"        => $cashId,
            "projectId"     => $projectId,
        );
        $where        = search(array("=" => $assetField));
        $assistWhere  = " and a.orderId = '$subjectId'";
        $voucherWhere = " and subjectId = '$subjectId'";
        //期初金额
        $jieInit = find(array('table' => "subject_assist as a join subject as b on a.orderId = b.id", 'single' => "b.direction = '借'" . $where . $assistWhere, 'field' => "ifnull(sum(a.initMoney),0) as money,ifnull(sum(a.initNum),0) as num"));
        $daiInit = find(array('table' => "subject_assist as a join subject as b on a.orderId = b.id", 'single' => "b.direction = '贷'" . $where . $assistWhere, 'field' => "ifnull(sum(a.initMoney),0) as money,ifnull(sum(a.initNum),0) as num"));
        //凭证
        $jieVoucher          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' and a.coid = '" . self::$coid . "' $voucherWhere and b.direction = '借' and date_format(a.recordDate,'%Y-%m') < '$startMonth'" . $where));
        $daiVoucher          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' and a.coid = '" . self::$coid . "' $voucherWhere and b.direction = '贷' and date_format(a.recordDate,'%Y-%m') < '$startMonth'" . $where));
        $jieVoucher['money'] = self::centToYuan($jieVoucher['money']) + $jieInit['money'];
        $daiVoucher['money'] = self::centToYuan($daiVoucher['money']) + $daiInit['money'];
        $jieVoucher['num']   += $jieInit['num'];
        $daiVoucher['num']   += $daiInit['num'];

        if ($jieVoucher['money'] == $daiVoucher['money'] && ($jieVoucher['money'] == 0)) {
            $jieMoney = 0;
            $daiMoney = 0;
            $balance  = 0;
        } elseif ($jieVoucher['money'] > $daiVoucher['money']) {
            $jieMoney = $balance = $jieVoucher['money'] - $daiVoucher['money'];
            $daiMoney = 0;
        } else {
            $jieMoney = 0;
            $daiMoney = $balance = $daiVoucher['money'] - $jieVoucher['money'];
        }

        if ($jieVoucher['num'] > $daiVoucher['num']) {
            $jieNum = $jieVoucher['num'] - $daiVoucher['num'];
            $daiNum = 0;
        } else {
            $daiNum = $daiVoucher['num'] - $jieVoucher['num'];
            $jieNum = 0;
        }
        $result = [
            'jieNum'   => voucherEditClass::formatZero($jieNum),
            'jiePrice' => accountDetailsClass::division($balance, $jieNum),
            'daiPrice' => accountDetailsClass::division($balance, $daiNum),
            'daiNum'   => voucherEditClass::formatZero($daiNum),
            'jieMoney' => round($jieMoney, 2),
            'daiMoney' => round($daiMoney, 2)
        ];
        if (self::$isFormat) {
            $result = accountDetailsClass::formatArrayNumber($result);
        }
        return $result;
    }


    /**
     * 本期合计
     */
    public function monthBalance($khid, $supplierId, $staffId, $departmentId, $materialId, $cashId, $projectId, $startMonth, $endMonth, $subjectId): array
    {
        $assetField       = array(
            "khid"          => $khid,
            "supplierId"    => $supplierId,
            "staffId"       => $staffId,
            "departmentId"  => $departmentId,
            "materialId" => $materialId,
            "cashId"        => $cashId,
            "projectId"     => $projectId,
        );
        $where            = search(array("=" => $assetField));
        $voucherWhere     = " and subjectId = '$subjectId'";
        $jieInit          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' and a.coid = '" . self::$coid . "' $voucherWhere and b.direction = '借' and date_format(a.recordDate,'%Y-%m') >= '$startMonth' and date_format(a.recordDate,'%Y-%m') <= '$endMonth'" . $where));
        $daiInit          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' and a.coid = '" . self::$coid . "' $voucherWhere and b.direction = '贷' and date_format(a.recordDate,'%Y-%m') >= '$startMonth' and date_format(a.recordDate,'%Y-%m') <= '$endMonth'" . $where));
        $jieInit['money'] = self::centToYuan($jieInit['money']);
        $daiInit['money'] = self::centToYuan($daiInit['money']);
        $result           = [
            'jieNum'   => voucherEditClass::formatZero($jieInit['num']),
            'jiePrice' => accountDetailsClass::division($jieInit['money'], $jieInit['num']),
            'daiPrice' => accountDetailsClass::division($daiInit['money'], $daiInit['num']),
            'daiNum'   => voucherEditClass::formatZero($daiInit['num']),
            'jieMoney' => round($jieInit['money'], 2),
            'daiMoney' => round($daiInit['money'], 2)
        ];
        if (self::$isFormat) {
            $result = accountDetailsClass::formatArrayNumber($result);
        }
        return $result;
    }

    /**
     * 计算余额
     * @param $khid
     * @param $supplierId
     * @param $staffId
     * @param $departmentId
     * @param $materialId
     * @param $cashId
     * @param $projectId
     * @param $endMonth
     * @param $subjectId
     * @return array
     */
    public function balance($khid, $supplierId, $staffId, $departmentId, $materialId, $cashId, $projectId, $endMonth, $subjectId): array
    {
        $assetField   = array(
            "khid"          => $khid,
            "supplierId"    => $supplierId,
            "staffId"       => $staffId,
            "departmentId"  => $departmentId,
            "materialId" => $materialId,
            "cashId"        => $cashId,
            "projectId"     => $projectId,
        );
        $where        = search(array("=" => $assetField));
        $assistWhere  = " and a.orderId = '$subjectId'";
        $voucherWhere = " and subjectId = '$subjectId'";
        //期初金额
        $jieInit = find(array('table' => "subject_assist as a join subject as b on a.orderId = b.id", 'single' => "b.direction = '借'" . $where . $assistWhere, 'field' => "ifnull(sum(a.initMoney),0) as money,ifnull(sum(a.initNum),0) as num"));
        $daiInit = find(array('table' => "subject_assist as a join subject as b on a.orderId = b.id", 'single' => "b.direction = '贷'" . $where . $assistWhere, 'field' => "ifnull(sum(a.initMoney),0) as money,ifnull(sum(a.initNum),0) as num"));

        $jievoucher          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' $voucherWhere and a.coid = '" . self::$coid . "' and b.direction = '借' and date_format(a.recordDate,'%Y-%m') <= '$endMonth'" . $where));
        $daivoucher          = find(array("table" => "voucher as a join voucher_detail as b on a.id = b.orderId", 'field' => "ifnull(sum(b.money),0) as money,ifnull(sum(b.voucherNum),0) as num", "single" => "a.isTemplate = '否' $voucherWhere and a.coid = '" . self::$coid . "' and b.direction = '贷' and  date_format(a.recordDate,'%Y-%m') <= '$endMonth'" . $where));
        $jievoucher['money'] = self::centToYuan($jievoucher['money']) + $jieInit['money'];
        $daivoucher['money'] = self::centToYuan($daivoucher['money']) + $daiInit['money'];
        if ($jievoucher['money'] > $daivoucher['money']) {
            $jieMoney = $jievoucher['money'] - $daivoucher['money'];
            $daiMoney = 0;
        } else {
            $jieMoney = 0;
            $daiMoney = abs($jievoucher['money'] - $daivoucher['money']);
        }
        $balance           = $jievoucher['money'] - $daivoucher['money'];
        $jievoucher['num'] += $jieInit['num'];
        $daivoucher['num'] += $daiInit['num'];
        if ($jievoucher['num'] > $daivoucher['num']) {
            $jieNum = $jievoucher['num'] - $daivoucher['num'];
            $daiNUm = 0;
        } else {
            $daiNUm = abs($jievoucher['num'] - $daivoucher['num']);
            $jieNum = 0;
        }
        $result = [
            'jieNum'   => voucherEditClass::formatZero($jieNum),
            'daiNum'   => voucherEditClass::formatZero($daiNUm),
            'jiePrice' => accountDetailsClass::division($jieMoney, $jieNum),
            'daiPrice' => accountDetailsClass::division($daiMoney, $daiNUm),
            'jieMoney' => round($jieMoney, 2),
            'daiMoney' => round($daiMoney, 2),
            'balance'  => round($balance, 2),
        ];
        if (self::$isFormat) {
            $result = accountDetailsClass::formatArrayNumber($result);
        }
        return $result;
    }


    /**
     * 导出
     */
    public function exportData()
    {
        if (!$this->power(self::page, 'export')) {
            $_SESSION['warn'] = '你还没有导出的权限';
        } else {
            $tr         = [];
            $sql        = static::rGet(self::$stid . self::page . 'sql');
            $time       = static::rGet(self::$stid . self::page . 'time');
            $arr        = $time ? explode(' ~ ', $time) : [date('Y-m', strtotime(accountDetailsClass::getMinDate())), date('Y-m', strtotime(accountDetailsClass::getMaxDate()))];
            $startMonth = trim($arr[0]);
            $endMonth   = end($arr);
            $title      = array("客户编码", "客户名称", "供应商编码", "供应商名称", "员工编码", "员工名称", "部门编码", "部门名称", "存货编码", "存货名称", "现金流编码", "现金流名称", "项目编码", "项目名称", "借方期初余额", "贷方期初余额", '借方本期发生额', '贷方本期发生额', '借方期末余额', '贷方期末余额');
            //获取查询结果
            $all = sqlFind($sql);
            foreach ($all as $array) {
                $kehu        = query('kehu', "khid = '$array[khid]'");
                $supplier    = query('supplier', "id = '$array[supplierId]'");
                $staff       = query('staff', "stid = '$array[staffId]'");
                $department  = query('department', "id = '$array[departmentId]'");
                $material    = query('material', "id = '$array[materialId]'");
                $cash        = query('cash', "id = '$array[cashId]'");
                $project     = query('project', "id = '$array[projectId]'");
                $initResult  = $this->initMoney($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $startMonth, $array['subjectId']);
                $monthResult = $this->monthBalance($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $startMonth, $endMonth, $array['subjectId']);
                $balance     = $this->balance($array['khid'], $array['supplierId'], $array['staffId'], $array['departmentId'], $array['materialId'], $array['cashId'], $array['projectId'], $endMonth, $array['subjectId']);
                $tr[]        = array($kehu['orderNo'], $kehu['companyName'], $supplier['code'], $supplier['name'], $staff['orderNo'], $staff['name'],
                    $department['orderNo'], $department['name'], $material['code'], $material['name'], $cash['code'], $cash['name'], $project['orderNo'],
                    $project['name'], $initResult['jieMoney'], $initResult['daiMoney'], $monthResult['jieMoney'],
                    $monthResult['daiMoney'], $balance['jieMoney'], $balance['daiMoney']);
            }
            $text = $this->control['name'] . "导出了" . self::title;
            $this->logText(["type" => self::page, "text" => $text]);
            $this->excelOut($title, $tr, self::title . ".xlsx");
        }
        header("Location:" . getenv("HTTP_REFERER"));
        exit(0);
    }
}

